using System;

namespace Matrix.Configuration.DTOs
{
    /// <summary>
    /// 缓存统计信息DTO
    /// </summary>
    public class CacheStatisticsDto
    {
        /// <summary>
        /// 总缓存项数量
        /// </summary>
        public int TotalItems { get; set; }

        /// <summary>
        /// 缓存命中数量
        /// </summary>
        public long HitCount { get; set; }

        /// <summary>
        /// 缓存未命中数量
        /// </summary>
        public long MissCount { get; set; }

        /// <summary>
        /// 缓存命中率（百分比）
        /// </summary>
        public double HitRate => HitCount + MissCount > 0 ? (double)HitCount / (HitCount + MissCount) * 100 : 0;

        /// <summary>
        /// 缓存设置数量
        /// </summary>
        public long SetCount { get; set; }

        /// <summary>
        /// 缓存删除数量
        /// </summary>
        public long RemoveCount { get; set; }

        /// <summary>
        /// 缓存清理数量
        /// </summary>
        public long ClearCount { get; set; }

        /// <summary>
        /// 最后更新时间
        /// </summary>
        public DateTime LastUpdateTime { get; set; }

        /// <summary>
        /// 缓存项过期数量
        /// </summary>
        public long ExpiredCount { get; set; }

        /// <summary>
        /// 缓存项平均存活时间（秒）
        /// </summary>
        public double AverageLifetimeSeconds { get; set; }

        /// <summary>
        /// 内存使用量（字节）
        /// </summary>
        public long MemoryUsageBytes { get; set; }

        /// <summary>
        /// 按命名空间分组的统计信息
        /// </summary>
        public System.Collections.Generic.List<NamespaceCacheStatisticsDto> NamespaceStatistics { get; set; } = new();
    }

    /// <summary>
    /// 命名空间缓存统计信息
    /// </summary>
    public class NamespaceCacheStatisticsDto
    {
        /// <summary>
        /// 命名空间名称
        /// </summary>
        public string Namespace { get; set; } = string.Empty;

        /// <summary>
        /// 该命名空间的缓存项数量
        /// </summary>
        public int ItemCount { get; set; }

        /// <summary>
        /// 该命名空间的命中数量
        /// </summary>
        public long HitCount { get; set; }

        /// <summary>
        /// 该命名空间的未命中数量
        /// </summary>
        public long MissCount { get; set; }

        /// <summary>
        /// 该命名空间的命中率（百分比）
        /// </summary>
        public double HitRate => HitCount + MissCount > 0 ? (double)HitCount / (HitCount + MissCount) * 100 : 0;

        /// <summary>
        /// 最后访问时间
        /// </summary>
        public DateTime? LastAccessTime { get; set; }
    }
}